package com.xframe.common.core.exception;

import org.springframework.http.HttpStatus;

import java.io.PrintWriter;
import java.io.StringWriter;

public class AbstractException extends RuntimeException{

    private static final long serialVersionUID = 1L;

    protected final HttpStatus status;

    /**
     * 错误码
     */
    protected int code;

    /**
     * 错误消息
     */
    protected String message;

    /**
     * 错误消息明细
     */
    protected String detailMessage;


    public AbstractException(HttpStatus status) {
        this.status = status;
        this.code = 0;
        this.message = null;
        this.detailMessage = null;
    }

    public AbstractException(HttpStatus status, int code,String message) {
        this.status = status;
        this.code = code;
        this.message = message;
        this.detailMessage = null;
    }

    public AbstractException(HttpStatus status, int code,String message,String detailMessage) {
        this.status = status;
        this.code = code;
        this.message = message;
        this.detailMessage = detailMessage;
    }



    private String toStackTrace(Throwable e) {
        StringWriter errorStackTrace = new StringWriter();
        e.printStackTrace(new PrintWriter(errorStackTrace));
        return errorStackTrace.toString();
    }

    public HttpStatus getStatus() {
        return status;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public String getDetailMessage() {
        return detailMessage;
    }

    public int getCode() {
        return code;
    }

}
